package com.shameit.goodqrinfomanager.source.http;



import com.shameit.goodqrinfomanager.bean.litepal.CangKu;
import com.shameit.goodqrinfomanager.bean.litepal.CangWei;
import com.shameit.goodqrinfomanager.bean.litepal.ChanPin;
import com.shameit.goodqrinfomanager.bean.litepal.JingXiaoShang;
import com.shameit.goodqrinfomanager.bean.litepal.LoginUser;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import me.goldze.mvvmhabit.http.BaseResponse;
import okhttp3.RequestBody;


/**
 * Created by goldze on 2019/3/26.
 */
public class HttpDataSourceImpl implements HttpDataSource {
    private ApiService apiService;
    private volatile static HttpDataSourceImpl INSTANCE = null;

    public static HttpDataSourceImpl getInstance(ApiService apiService) {
        if (INSTANCE == null) {
            synchronized (HttpDataSourceImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new HttpDataSourceImpl(apiService);
                }
            }
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }

    private HttpDataSourceImpl(ApiService apiService) {
        this.apiService = apiService;
    }

    @Override
    public Observable<BaseResponse<LoginUser>> login(RequestBody body) {
//        return Observable.just(new Object()).delay(3, TimeUnit.SECONDS);


        return WebClient.getInstance().getApiService().login(body);
    }

    @Override
    public Observable<BaseResponse<List<CangKu>>> syncCangku(RequestBody requestBody) {
        return WebClient.getInstance().getApiService().syncCangku(requestBody);
    }

    @Override
    public Observable<BaseResponse<List<CangWei>>> syncCangwei() {
        return WebClient.getInstance().getApiService().syncCangwei();
    }

    @Override
    public Observable<BaseResponse<List<JingXiaoShang>>> syncJxs() {
        return WebClient.getInstance().getApiService().syncJinxiaoshang();
    }

    @Override
    public Observable<BaseResponse<List<ChanPin>>> syncChanpin() {
        return WebClient.getInstance().getApiService().syncChanpin();
    }

    @Override
    public Observable<BaseResponse<Boolean>> uploadBarBind(RequestBody requestBody) {
        return WebClient.getInstance().getApiService().uploadBarBind(requestBody);
    }
}
